package cs275.ants.graph;

import junit.framework.TestCase;
import cs275.ants.graph.MazeCell.Wall;

public class MazeCellTest extends TestCase {

	private MazeCell cell;

	@Override
	protected void setUp() throws Exception {
		cell = new MazeCell();
	}
	
	public void testToDebugString() {
		assertEquals("[LURD]", cell.toDebugString());
		
		cell.knockDownWall(Wall.UP);
		assertEquals("[L_RD]", cell.toDebugString());
		
		cell.knockDownWall(Wall.DOWN);
		assertEquals("[L_R_]", cell.toDebugString());
	}
	
	public void testConstructor() {
		assertTrue(cell.walls.contains(Wall.LEFT));
		assertTrue(cell.walls.contains(Wall.DOWN));
		assertTrue(cell.walls.contains(Wall.RIGHT));
		assertTrue(cell.walls.contains(Wall.UP));
	}
	
	public void testKnockDownWall_LEFT() {
		cell.knockDownWall(Wall.LEFT);
		assertFalse(cell.walls.contains(Wall.LEFT));
		assertTrue(cell.walls.contains(Wall.NONE));
	}
	
	public void testKnockDownWall_RIGHT() {
		cell.knockDownWall(Wall.RIGHT);
		assertFalse(cell.walls.contains(Wall.RIGHT));
		assertTrue(cell.walls.contains(Wall.NONE));
	}
	public void testKnockDownWall_UP() {
		cell.knockDownWall(Wall.UP);
		assertFalse(cell.walls.contains(Wall.UP));
		assertTrue(cell.walls.contains(Wall.NONE));
	}
	public void testKnockDownWall_DOWN() {
		cell.knockDownWall(Wall.DOWN);
		assertFalse(cell.walls.contains(Wall.DOWN));
		assertTrue(cell.walls.contains(Wall.NONE));
	}
	
	public void testHasAllWalls() {
		assertTrue(cell.hasAllWalls());
		cell.knockDownWall(Wall.RIGHT);
		assertFalse(cell.hasAllWalls());
	}
	
	public void testHasWall() { 
		assertFalse(cell.hasWall(Wall.NONE));
		assertTrue(cell.hasWall(Wall.UP));
		assertTrue(cell.hasWall(Wall.DOWN));
		assertTrue(cell.hasWall(Wall.LEFT));
		assertTrue(cell.hasWall(Wall.RIGHT));
		cell.knockDownWall(Wall.RIGHT);
		assertFalse(cell.hasWall(Wall.RIGHT));;
	}
	
	public void testKnockDown_AdjWall() {
		MazeCell adjCell = new MazeCell();
		adjCell.column = 1;
		
		cell.knockDownWall(adjCell);
		assertFalse(cell.walls.toString(), cell.walls.contains(Wall.RIGHT));
		assertFalse(adjCell.walls.toString(), adjCell.walls.contains(Wall.LEFT));
		
		
		MazeCell upLeftCornerCell = new MazeCell(); 
		MazeCell downCell = new MazeCell();
		MazeCell rightCell = new MazeCell();
		
		upLeftCornerCell.row = 0; 
		upLeftCornerCell.column = 0; 
	
		downCell.row = 1; 
		downCell.column = 0; 
		
		rightCell.row = 0; 
		rightCell.column = 1; 
		
		upLeftCornerCell.knockDownWall(rightCell);
		assertFalse(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.RIGHT));
		assertTrue(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.LEFT));
		assertTrue(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.UP));
		assertTrue(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.DOWN));

		assertFalse(rightCell.walls.toString(), rightCell.walls.contains(Wall.LEFT));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.RIGHT));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.UP));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.DOWN));
		
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.DOWN));
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.UP));
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.LEFT));
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.RIGHT));

		upLeftCornerCell.knockDownWall(downCell);
		assertFalse(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.RIGHT));
		assertTrue(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.LEFT));
		assertTrue(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.UP));
		assertFalse(upLeftCornerCell.walls.toString(), upLeftCornerCell.walls.contains(Wall.DOWN));

		assertFalse(rightCell.walls.toString(), rightCell.walls.contains(Wall.LEFT));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.RIGHT));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.UP));
		assertTrue(rightCell.walls.toString(), rightCell.walls.contains(Wall.DOWN));
		
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.DOWN));
		assertFalse(downCell.walls.toString(), downCell.walls.contains(Wall.UP));
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.LEFT));
		assertTrue(downCell.walls.toString(), downCell.walls.contains(Wall.RIGHT));

		
	}
}
